<template>
  <!-- 方案规划导航栏 -->
   <div style="width: 100%;height: 100%;text-align: center;">

 
  <div style="display: inline-flex;width: 100%;height: 10%;margin-top: 1vh;text-align: left;">
    
    <div style="display: flex;" class="box">
 
      <el-form :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: 1vh;width: 91%;" class="demo-form-inline">
        <el-form-item label="氢⽓负荷数据类型:">

          <el-radio-group @change="radioChange" v-model="importType">
            <el-radio label="1">日均氢气负荷</el-radio>
            <el-radio label="2">逐时氢气负荷</el-radio> 
          </el-radio-group>

        </el-form-item>

        <el-form-item v-if="this.importType==1" label="">
          <el-input style="width: 90%;" v-model="hourHydrogenLoad">
              <template slot="append">kg/day</template>
            </el-input>
        </el-form-item>

      
      </el-form>
      
      <div style="margin-top: 0.7vh;width: 17%;margin-right: 1vh;">
        <el-button type="primary" v-show="this.importType=='1'" @click="savePageData()" style="width: 110px;float: right;">
          <span class="button-text">保存</span>
        </el-button>
        <el-button type="primary" v-show="this.importType!='1'" @click="uploadData()" style="width: 110px;float: right;">
          <span class="button-text">上传</span>
        </el-button>
      </div>

       
    </div>

  </div>

  <div class="box1">
     <div id="lineCharts" style="width: 98%;height: 98%;margin: 0 auto;"></div>
  </div>
  
  <div class="box2">

    <el-table :data="tableData" style="width: 98%;height:90%;overflow-y: scroll;margin-top: 1vh;margin: 1vh auto;text-align: center;">
      <el-table-column
        prop="timeInfo"
        label="时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="valueInfo"
        label="氢气负荷"
        width="180">
      </el-table-column>
       
    </el-table>

  </div>

        
  <!-- 上传弹窗 -->
  <div>
    <el-dialog :title="dialogTitle" :visible.sync="dialogShowFlag"  width="80vh" align="left">
      
      <div class="uploadModal">
        
        <div class="modal-body">
          
          <el-link style="color: #2e44ff;font-size: 1vw;" @click="downloadTemp()" class="modal-description">下载模版，填写信息</el-link>
          <button class="upload-area">
            <span class="upload-area-icon">
              <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="340.531" height="419.116" viewBox="0 0 340.531 419.116">
                <g id="files-new" clip-path="url(#clip-files-new)">
                  <path id="Union_2" data-name="Union 2" d="M-2904.708-8.885A39.292,39.292,0,0,1-2944-48.177V-388.708A39.292,39.292,0,0,1-2904.708-428h209.558a13.1,13.1,0,0,1,9.3,3.8l78.584,78.584a13.1,13.1,0,0,1,3.8,9.3V-48.177a39.292,39.292,0,0,1-39.292,39.292Zm-13.1-379.823V-48.177a13.1,13.1,0,0,0,13.1,13.1h261.947a13.1,13.1,0,0,0,13.1-13.1V-323.221h-52.39a26.2,26.2,0,0,1-26.194-26.195v-52.39h-196.46A13.1,13.1,0,0,0-2917.805-388.708Zm146.5,241.621a14.269,14.269,0,0,1-7.883-12.758v-19.113h-68.841c-7.869,0-7.87-47.619,0-47.619h68.842v-18.8a14.271,14.271,0,0,1,7.882-12.758,14.239,14.239,0,0,1,14.925,1.354l57.019,42.764c.242.185.328.485.555.671a13.9,13.9,0,0,1,2.751,3.292,14.57,14.57,0,0,1,.984,1.454,14.114,14.114,0,0,1,1.411,5.987,14.006,14.006,0,0,1-1.411,5.973,14.653,14.653,0,0,1-.984,1.468,13.9,13.9,0,0,1-2.751,3.293c-.228.2-.313.485-.555.671l-57.019,42.764a14.26,14.26,0,0,1-8.558,2.847A14.326,14.326,0,0,1-2771.3-147.087Z" transform="translate(2944 428)" fill="var(--c-action-primary)"/>
                </g>
              </svg>
            </span>
            <span class="upload-area-title">请选择您要上传的文件，仅支持xls,xlsx格式文件</span>
            <span class="upload-area-description">
              <br/><strong @click="goFile()">点击上传</strong>
            </span>
          </button>
        </div>
        <form style="display: none;" enctype="multipart/form-data">
            <input type="file" id="file" name="file" ref="files" @change="importData($event)"
                accept=".xls,.xlsx" />
        </form>
        <div class="modal-footer">
          <!-- <el-button type="primary" @click="confirmUpload()">确认上传</el-button> -->
          <el-button type="primary" @click="closeWindow()">取消</el-button>
        </div>
      </div>

 
    </el-dialog>
  </div>
  <!-- 上传弹窗 -->


</div>
  
</template>

<script>

  // 引入基本模板,按需加载
  let echarts = require('echarts/lib/echarts');
 
  import '../../assets/css/reset.min.css';
  import '../../assets/css/uploadCss.css';
  
let axisData = ['1日','2日','3日','4日','5日','6日','7日','8日','9日','10日','11日','12日','13日','14日','15日','16日','17日','18日','19日','20日','21日','22日','23日','24日','25日','26日','27日','28日','29日','30日']
let seriesData = [
   [92.8872,92.6444,89.7734,97.2053,93.2683,92.2416,95.2624,86.5186,91.2479,91.3806,91.8299,89.3534,92.4887,86.9958,91.6448,92.3078,91.348,92.1586,89.9026,92.529,90.6807,88.1117,90.8095,90.1901,89.3808,92.44,91.5109,90.9205,90.3345,94.7832
]
]

var lineOption = {
   //backgroundColor: '#0F224C', //背景色
   title: {
		text: '',
		textStyle: {
			color: '#FFF',
			fontSize: 20
		},
		top:"2%",
		left: 'center',
// 		right: '5%'
	},
   grid: {
      left : '3%',
      right : '5%',
      bottom : '5%',
      top : '20%',
      containLabel: true
   },
   tooltip: {
      trigger: "axis",
      axisPointer: {
         lineStyle: {
            color: "rgba(255,255,255,0.7)"
         }
      },
      backgroundColor: "rgba(255,255,255,0.1)",
      padding: [5, 10],
      textStyle: {
         color: "rgb(255,255,255)"
      }
   },
   legend: {
      x: "center",
      y: "bottom",
      icon: "circle",
      itemWidth: 12,
      itemHeight: 12,
      itemGap: 60,
      textStyle: {
         color: "#C0C4CC",
         fontSize: 13,
         fontWeight: 'bold',
      },
      data: [""]
   },
   xAxis: {
      name: '(小时)', 
      nameTextStyle: {
        color: '#f2f2f2',
        padding: [0, 20, -5, 0]
      },
      type: "category",
      data: axisData,
      boundaryGap: true,
      splitLine: {
         show: false
      },
      axisTick: {
         show: false
      },
      // type: 'dashed',
      axisLine: {
         lineStyle: {
            type: 'dashed',
            color: "#2557B4"
         }
      },
      axisLabel: {
         margin: 10,
         textStyle: {
            fontSize: 14,
            color: "#C0C4CC"
         }
      }
   },
   yAxis: [
      {
         type: "value",
         position: "center",
         name: '（kg）',
         scale : true,
         nameTextStyle: {
            padding: [0, 0, 0, 0],
            color: '#C0C4CC',
            fontSize: 13,
            fontWeight: 'bold',
            // lineHeight: 40,
         },
         splitLine: {
            show: true,
            lineStyle: {
               type: 'dashed',
               color: "#C0C4CC"
            }
         },
         axisLine: {
            show: true,
            lineStyle: {
               color: "rgba(255,255,255,0.3)"
            }
         },

         axisLabel: {
            show: true,
            margin: 2,
            textStyle: {
               fontSize: 12,
               color: "#DEEBFF"
            }
         }
      },],
   series: [
      {
         name: "数据",
         type: "line",
         smooth: true,
         showSymbol: false,
         symbol: 'circle',
         // showSymbol: true,
         // symbol: 'circle',
         data: seriesData,
         itemStyle: {
            normal: {
               color: '#287CE8'
            }
         },
         lineStyle: {
            normal: {
               width: 3
            }
         },


      }
      
   ]
}



  export default {
    name: 'hydrogenGasLoadPht',
    data() {
      return {
        hourHydrogenLoad : "",
        projectId : "",
  
        tableData: [],
        activeDate: '',
        type: '',
        hydrogenGasLoad : {},
        importType:"",
        dialogTitle : "上传负荷数据",
        dialogShowFlag : false,
        templateName : "hydrogenGasLoadPht.xlsx",
        uploadUrl : "/iepsapi/ea/hpEconomicAnalysis/importLoadPowerData"
      }
    },
    mounted: function() {
      //获取项目id
      this.projectId = this.$route.query.projectId;
      this.queryHydrogenGasLoad();
    },
    methods: {

      uploadData : function(){
        this.dialogShowFlag = true;
      },

      closeWindow : function(){
        this.dialogShowFlag = false;
      },

      goFile() {
          this.$refs.files.click();
      },
      downloadTemp: function () { 
          window.open('/iepsapi/ea/hpEconomicAnalysis/downloadTemp?templateName=' + this.templateName, '_self');
      },
      
      //导入
      importData: function (file) {
          var vm = this;
          var files = file.target.files[0];
          var fileName = files.name;
          if (!files) {
              return;
          }
          if (files.type === "application/vnd.ms-excel" || files.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
              var formData = new FormData();
              formData.append('file', file.target.files[0]);
              formData.append('fileName', fileName);
              formData.append('importType', vm.importType);
              formData.append('id', vm.id);
              const loading = this.$loading({
                  lock: true,
                  text: "正在导入...",
                  spinner: "hy-icon-loading",
                  background: "rgba(0, 0, 0, 0.7)",
              });
              $.ajax({
                  type: 'post',
                  url: vm.uploadUrl,
                  data: formData,
                  cache: false,
                  processData: false,
                  contentType: false,
                  timeout: 300000, // 设置超时时间为300000毫秒（即5分钟） 
                  success: function (res) {
                      //成功执行的代码
                      loading.close();
                      var state = res.state;
                      if (state == 'error') {
                
                          vm.$message({
                            message: res.message,
                            type: 'info'
                          });
                      } else {
                  
                          vm.$message({
                            message: '导入成功',
                            type: 'success'
                          });
                          vm.dialogShowFlag = false;
                      }
                      setTimeout(() => {
                          vm.queryHydrogenGasLoad();;
                      }, 1000);



                  },
                  error: function (xhr, textStatus, errorThrown) {
                      loading.close();
                      // 处理超时错误
                      if (textStatus == 'timeout') {
                          // 超时后的处理逻辑
                          vm.$message({
                            message: '后台导入中',
                            type: 'info'
                          });
                      } else {
                          vm.$message({
                            message: '导入失败',
                            type: 'error'
                          });
                      }
                  }
              })
          } else {
              this.$message({
                  message: '文件格式错误！',
                  type: 'error'
              });
              return;
          }
      },

            
      savePageData : function(){
 
        var vm = this;

        this.hydrogenGasLoad.hourHydrogenLoad = this.hourHydrogenLoad;
        this.hydrogenGasLoad.importType = "1";
        this.hydrogenGasLoad.projectId = this.projectId;
        this.hydrogenGasLoad.type = "hydrogenGasLoadPht";

        this.$http.post('/iepsapi/ea/hpEconomicAnalysis/savePageData', {
          "pageData": JSON.stringify(this.hydrogenGasLoad),
          "tableName":"hydrogen_load"
        }).then((res) => {
         
        });

      },

      radioChange : function(){
        //alert(this.dataType);
      },
      queryHydrogenGasLoad : function(){
                
        var vm = this;

        this.$http.post('/iepsapi/ea/hpEconomicAnalysis/queryHydrogenGasLoad?projectId='+this.projectId+"&type=hydrogenGasLoadPht").then((res) => {
          var result = res.data;
          if(result){
          
            vm.id = result.hydrogenGasLoad.id;

            vm.importType = result.hydrogenGasLoad.importType;
            vm.hourHydrogenLoad = result.hydrogenGasLoad.hourHydrogenLoad;

            vm.hydrogenGasLoad = result.hydrogenGasLoad;
            vm.tableData = result.tableDataArray;
            
            var xAxisData = result.xAxisData;
            var seriesData = result.seriesData;

            let lineCharts = this.$echarts.init(document.getElementById('lineCharts'))
      
            lineCharts.clear(); 

            lineOption.xAxis.data = xAxisData;
            lineOption.series[0].data = seriesData;

            lineCharts.setOption(lineOption); 

            window.onresize = function(){
              lineOption.resize(); 
            }

          }
        }).catch((error) => {
          console.log(error);
        });


      }, 
       
    }
  }
</script>



<style>



/* 
.el-table{
  background-color: rgb(20 34 78);
  color: #FFFFFF;
  border-color: rgb(24 63 124 / 51%);
  *{
    border-color: rgb(24 63 124 / 51%) !important;
  }
  .el-table__header-wrapper{
    tr{
      background-color: rgb(10 24 90 / 81%);
      th{
        color: #ffffff;
        background-color: rgba(0,0,0,0.4);
      }
    }
  }
  .el-table__body-wrapper{
    tr{
      background-color: rgb(8 26 80 / 88%);
      &:hover>td{      
        background-color: rgb(13 30 80);
      }
    }
  }
} */
  .el-form--inline .el-form-item__content {
      display: inline-block;
      vertical-align: middle;
      margin-left: 1vh;
  }

  .el-radio {
      color: #eff4ff;
      cursor: pointer;
      margin-right: 30px;
  }

  .el-form-item {
      margin-bottom: 5px;
  }
  .el-form-item__label {
      text-align: right;
      vertical-align: middle;
      float: left;
      font-size: 14px;
      color: #f2f2f2;
      line-height: 40px;
      padding: 0 1px 0 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
  }
  .el-input__inner { 
      background-color: #202b6180;
      background-image: none;
      border-radius: 4px;
      border: 1px solid #5c7bc5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      color: #a3aec5;
      display: inline-block;
      font-size: inherit;
      height: 40px;
      line-height: 40px;
      outline: 0;
      padding: 0 15px;
      -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      width: 100%;
  }

  .el-input-group__append, .el-input-group__prepend {
    background-color: #305997;
    color: #ffffff;
    vertical-align: middle;
    display: table-cell;
    position: relative;
    border: 1px solid #506aa7;
    border-radius: 4px;
    padding: 0 20px;
    width: 1px;
    white-space: nowrap;
  }
</style>

 

<style scoped> 
  /deep/ .el-dialog__body {
      padding: 0px 0px;
      color: #606266;
      font-size: 14px;
      word-break: break-all;
  }

  /* 设定地图的大小 */
  #allmap{
    height: 350px;
    width: 100%;
  }

  .buttonStyle {
    height: 4vh;
    width: 24vh;
    display: inline-block;
    -webkit-border-radius: 60px;
    -moz-border-radius: 60px;
    cursor: pointer;
    border-radius: 10px;
    font-family: Arial;
    border: none;
    color: #ffffff;
    font-size: 1.6vh;
    background: #1f2c6c3b;
    border-bottom: 1px solid rgb(64, 158, 255);
    margin: 1.5vh 10px;
    text-align: center;
    line-height: 4vh;
    vertical-align: middle;
    text-decoration: none;
  }

  .box{ 
    width: 98%;
    height: 6vh;
    margin: auto;
    border-radius: 5px;
    margin: auto;
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
  }

  .box1{ 
    width: 96%;
    height: 30vh;
    margin-top: 1vh;
    margin: 0 auto;
    top: 18vh;
    left: 3.5vh;
    position: absolute;
    border-radius: 5px;
    margin: auto;
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
  }

  .box2{ 
    width: 96%;
    height: 29vh;
    margin-top: 1vh;
    margin: 0 auto;
    top: 49.5vh;
    left: 3.5vh;
    position: absolute;
    border-radius: 5px; 
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
  }

  .titleCss{
    font-size: 22px;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.2;
    color: #f2f2f2;
  }
</style>
